package com.olt.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class MvcConfig implements WebMvcConfigurer {


    ApplicationHome application = new ApplicationHome(getClass());

    /**
     * 静态资源处理
     **/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        File file = new File(application.getSource().getParentFile().toString() + "/upload/");
        if (!file.exists()) {
            file.mkdirs();
        }
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + application.getSource().getParentFile().toString() + "/upload/");
    }
}
